<!--添加修改角色信息-->
<template>
    <a-modal v-model="showModel" :mask-closable="false" :closable="false" :width="520" title="选择角色" @cancel="cancelApply">
        <a-form :label-width="100" layout="inline"  class="modelSearch">
            <a-form-item label="角色名称：">
                <a-select v-model="roleId" style="width:320px" allowClear placeholder="请选择角色" >
                    <a-select-option v-for="item in roles" :value="item.value" :key="item.value">{{ item.label}}
                    </a-select-option>
                </a-select>
            </a-form-item>
        </a-form>
        <div slot="footer">
            <a-button type="default" size="default" @click="cancelApply()">取消</a-button>
            <a-button type="primary" size="default" @click="saveApply()">确定</a-button>
        </div>
    </a-modal>
</template>

<script>


    export default {
        name: 'copyRole',
        data () {
            return {
                showModel: false,
                roles: [],
                roleId: ''
            }
        },
        props: {
            currentRoleId: {
                type: String,
                required: true
            }
        },
        methods: {
            /*打开弹框*/
            showModal () {
                this.showModel = true
            },
            saveApply () {
                this.$emit ('loadCopyRoleRes', this.roleId)
                this.showModel = false
            },
            cancelApply () {
                this.showModel = false
            }
        },
        created () {
            // 加载角色列表
            this.$store.dispatch ('loadRolesAct').then (response => {
                this.roles = response
                /**
                 * 确定当前角色的偏移量
                 */
                let offsetIndex = -1
                this.roles.forEach (( item, index ) => {
                    if (item.value === this.currentRoleId) {
                        offsetIndex = index
                    }
                })

                /**
                 * 移除当前被操作的角色
                 */
                if (offsetIndex >= 0) {
                    this.roles.splice (offsetIndex, 1)
                }
            })
        }
    }
</script>
